
import { evalFormula,FORMULA_MATHS } from 'formula-editor-vue3'
import {customFormulaFun,custumVariablesFun} from '@/framework-core/utils/formulaData';

const mixFormula = {
  data() {
    return {
    };
  },
  methods: {
    getFormulaResult(column,viewFormData){
      let custumData = viewFormData.form;
      let customMathList =[];
      FORMULA_MATHS.map((d) => {
        customMathList.push(d)
      })
      let customFormulaDataList = customFormulaFun();
      customFormulaDataList.map((d) => {
        customMathList.push(d)
      })
      custumData.$loginInfo =  viewFormData.param;
      custumData.$routeQueryInfo =  viewFormData.routeQuerys;
      custumData.$dic ={};
      if(viewFormData.dics){
        for (let ikey in viewFormData.dics){
          custumData.$dic[ikey] = {};
          let ll = viewFormData.dics[ikey];
          if(ll){
            for(let dindex =0;dindex<ll.length;dindex++){
              custumData.$dic[ikey][ll[dindex].value] = ll[dindex].label
            }
          }

        }
      }
      //custumData.$dic =  viewFormData.dics;

      try {
        return  evalFormula(
            column.formula,
            text => {
              return `['${text}']`
            },
            custumData,
            customMathList
        )
      } catch (error) {
        console.error('formula error >>>', error)
        return "";
        //this.$message.error('formula error >>>', error);
      }
    }
  }
};

export default mixFormula;
